package senders;
import java.rmi.RemoteException;
import java.util.ArrayList;

import main.Server;

import client.remote.ClientReceiver;


public class BroadCaster implements IBroadcaster
{
	private ChatBroadCaster chatBroadcaster;
	private GameBroadcaster gameBroadcaster;
	private Server server;
	public BroadCaster(Server server)
	{
		chatBroadcaster = new ChatBroadCaster(this,true);
		gameBroadcaster = new GameBroadcaster(this,server);
		this.server = server;
	}
	public synchronized ArrayList<ClientReceiver>  getClients()
	{
		return server.getClients();
	}
	public void shutdown()
	{
		chatBroadcaster.shutdown();
		gameBroadcaster.shutdown();
	}
	public void  bcMessage(String msg)
	{
		chatBroadcaster.addMessage(msg);
	}
	public void processGameRequest(ClientReceiver client)
	{
		gameBroadcaster.addPlayer(client);
	}
	public synchronized void broadcastMessage(String msg)
	{
		System.out.println("Sending to charBroadcaster");
		chatBroadcaster.addMessage(msg);
	}
	public void onGameJoinRequest(ClientReceiver client) 
	{
		gameBroadcaster.addPlayer(client);
	}
	@Override
	public void reportError(ClientReceiver client)
	{
		server.reportError(client);
		
	}
	public void removeClient(ClientReceiver client)
	{
		gameBroadcaster.removePlayer(client);
	}
}
